package hauwei.year2024.month4;

import java.util.*;

public class ComparePho {
    public static HashMap<Integer,Integer>remap=new HashMap<>();
    public static HashSet<Integer>set=new HashSet<>();
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][]phoMap=new int[n][n];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                phoMap[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<n;i++){
            List<Integer> list=new ArrayList<Integer>();
            if(!set.contains(i)){
                list.add(i);
                dfs(i,phoMap,i,0,list);
            }
        }
        sc.close();
        Iterator<Integer> iterator = remap.keySet().iterator();
        while(iterator.hasNext()){
            Integer key=iterator.next();
            System.out.print(remap.get(key));
            if(iterator.hasNext()){
                System.out.print(" ");
            }
        }
    }
    public static void dfs(int start, int[][]map, int i, int sum, List<Integer> list){
        int width=map[0].length;
        int height=map.length;
        int[]w=map[i];
        for(int k=1;k<w.length;k++){
            if(w[k]!=0&&!list.contains(k)){
                sum+=w[k];
                list.add(k);
                dfs(start,map,k,sum,list);
            }
        }
        if(!remap.containsKey(start)){
            remap.put(start,sum);
            set.addAll(list);
        }
    }
}
